package com.wzh.springbootinit.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Author wzh
 * @create 2023/3/31 22:21
 * @Description: knife4j是swagger的增强工具，默认集成swagger框架
 * 具体用法可参照： https://doc.xiaominfo.com/docs/quick-start
 * http://ip:port/doc.html
 * 注意此处,假如了应用访问路径，如果配置了应用访问路径，则需加上应用访问路径，否则会报404
 */
@Configuration
@EnableSwagger2
@Profile("dev")
public class Knife4jConfig {

    @Bean
    public Docket defaultApi2(){
         return new Docket(DocumentationType.SWAGGER_2)
                 .apiInfo(new ApiInfoBuilder()
                 .title("springboot-init")
                 .description("springboot-init")
                 .version("1.0")
                 .build())
                 .select()
//                 指定扫描包的路径
                 .apis(RequestHandlerSelectors.basePackage("com.wzh.springbootinit.controller"))
//                 表示选择所有的路径进行公开，.paths(PathSelectors.ant("/api/**"))表示只选择以/api/开头的路径进行公开。
                 .paths(PathSelectors.any())
                 .build();
    }
}
